package com.bit.java;

public class Test6 {

    public static void move(char p1, char p2) {
        System.out.print(p1 + " -> " + p2 + " ");
    }
    /*
    * pos1:起始位置
    * pos2:中转位置
    * pos3:终点位置
    * */
    public static void Htower(int n, char pos1, char pos2, char pos3) {
        if(n == 1) {
            move(pos1, pos3);
            return ;
        }
        Htower(n - 1, pos1, pos3, pos2);
        move(pos1, pos3);
        Htower(n - 1, pos2, pos1,pos3);
    }

    public static void main(String[] args) {
        // 用多组数据检测
        Htower(1,'A', 'B', 'C');
        System.out.println();
        Htower(2,'A', 'B', 'C');
        System.out.println();
        Htower(3,'A', 'B', 'C');
        System.out.println();
        Htower(4,'A', 'B', 'C');
        System.out.println();
        Htower(5,'A', 'B', 'C');
        System.out.println();
    }

}
